const app = getApp();
import api from "../../utils/apiInstance"
Page({
  data: {
    id: "",
    title: ""
  },
  onLoad: function (params) {

    if (params.id) {

      this.setData({
        id: params.id
      })
      console.log('this.data.searchParam', this.data.searchParam)

      this.loadData()
    }
    else if (params.urlParams) {
      try {
        this.setData({
          id: JSON.parse(params.urlParams).id
        })
      }
      catch (err) {
        wx.showModal({
          title: '提示',
          content: '无法解析JSON',
          success: function (res) {

          }
        })
      }
    }
    else {
      wx.showModal({
        title: '提示',
        content: '未获取到相关参数',
        success: function (res) {
          wx.reLaunch({
            url: '/pages/menu/menu',
          });
        }
      })
    }
  },


  async loadData() {
    const res = await api.get(`/v1/openApi/staff/course/${this.data.id}?type=1`) //1808779183401246722
    console.log('res', res.data);
    this.setData({
      title: res.data.name
    })
  },

  gotoLaoShi() {
    wx.navigateTo({
      url: `/pages/my-course/my-course?id=${this.data.id}`,
    })
  },
  gotoXueSheng() {
    wx.navigateTo({
      url: `/pages/my-exam-list/my-exam-list?id=${this.data.id}`,
    })
  }
});